package com.atguigu.nio;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel01 {

    public static void main(String[] args) throws IOException {

        String str = "hello inspur 浪潮";
        FileOutputStream fileOutputStream = new FileOutputStream("file01.txt");

        FileChannel fileChannel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

        byteBuffer.put(str.getBytes());

        byteBuffer.flip();

        // 将byteBuffer 写入到当前channel
        fileChannel.write(byteBuffer);
        fileOutputStream.close();

    }
}
